import request from "@/api";
import { BaseRet, ObjectRet } from "../response";

class LoginApi {
  /**
   * 登录
   * @param data
   * @returns
   */
  static async login(data: LoginForm): Promise<ObjectRet<LoginRet>> {
    return await request({
      url: "login/login",
      method: "post",
      data: data,
    });
  }

  /**
   * 退出登录
   * @param data
   * @returns
   */
  static async logout(): Promise<BaseRet> {
    return await request({
      url: "login/logout",
      method: "get",
    });
  }
}

export default LoginApi;

export interface LoginForm {
  userName: string;
  password: string;
}

export interface LoginRet {
  user: LoginUser;
  accessToken: string;
  refreshToken: string;
}

export interface LoginUser {
  id?: string;
  nickName?: string;
  userName?: string;
  email?: string;
  phone?: string;
  avatarId?: string;
  avatarUrl?: string;
}

export interface RefreshLoginRet {
  accessToken: string;
  refreshToken: string;
}
